
public class Sort {
	protected int m_count;
	protected Element m_next;
	protected Element[] m_array;
	
	public void setData(Element[] array) {
		m_count = array.length - 1;
		m_next = array[m_count]; //最后一个位置用于临时存放
		m_array = array;
	}
		
	public void printArray() {
		for(int i=0; i<m_count; ++i) {
			System.out.print(m_array[i].getKey() + "\t");
		}
		System.out.println("\n");
	}
	
	public void printList() {
		for(int i=0; i<m_count; ++i) {
			System.out.print(m_array[i].getLink() + "\t");
		}
		System.out.println("\n");
	}
	
	public void printTable() {
		for(int i=0; i<m_count; ++i) {
			System.out.print(m_array[i].getTable() + "\t");
		}
		System.out.println("\n");
	}
	
	public Element seqSearch(Element key) {
		for(int i=0; i<m_count; ++i) {
			if(m_array[i].eq(key)) return m_array[i];
		}
		
		return null;
	}
	
	public Element binSearch(Element key) {
		int left = 0;
		int right = m_count - 1;
		int middle;
		while(left <= right) {
			middle = (left+right)/2;
			if (m_array[middle].eq(key)) {
				return m_array[middle];
			} else if (m_array[middle].lt(key)) {
				left = middle + 1;
			} else {
				right = middle - 1;
			}
		}
		
		return null;
	}
}